<?php
/**
 * view controller
 * @package app-file_controller
 */
load_controller('/file');
/**
 * view controller
 * @author pandajingjing
 * @package app-file_controller
 */
class viewcontroller extends filecontroller{

	function doRequest(){
		load_lib('/bll/viewfile');
		$clsBll=new bll_viewfile();
		$bolErrFnd=false;
		$mixResult=$clsBll->suitDomain('file',$this->getParam('HTTP_HOST','server'));
		if(true===$mixResult){
			$strFromURL=$this->getParam('HTTP_REFERER','server');
			$mixResult=$clsBll->chkAllowedDomain($strFromURL);
			if(true===$mixResult){
				$arrParams=$this->getParams('url');
				$strMimeType='';
				switch(count($arrParams)){
					case 5:
						$mixResult=$clsBll->viewFile($arrParams[0],$arrParams[4],$strMimeType,$arrParams[1],$arrParams[2],$arrParams[3]);
						break;
					case 4:
						$mixResult=$clsBll->viewFile($arrParams[0],$arrParams[3],$strMimeType,$arrParams[1],$arrParams[2]);
						break;
					case 2:
						$mixResult=$clsBll->viewFile($arrParams[0],$arrParams[1],$strMimeType);
						break;
					default:
						$mixResult=false;
				}
				if(false===$mixResult){
					$bolErrFnd=true;
				}else{
					$this->addHeader('content-type:'.$strMimeType);
					$this->addHeader('Cache-Control:max-age=315360000');
				}
			}else{
				$bolErrFnd=true;
			}
		}else{
			$bolErrFnd=true;
		}
		if($bolErrFnd){
			$this->addHeader('DFS-Info:'.$mixResult);
			$this->addHeader('HTTP/1.0 404 Not Found');
		}
		$this->setData('bolErrFnd',$bolErrFnd);
		$this->setData('objFile',$mixResult);
		return '/view';
	}
}